home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-06-04 | 7.3 KB | 282 lines | [TEXT/MPS ] |
- /*
- * File: MiscServices.cp
- *
- * Contains: xxx put contents here xxx
- *
- * Written by: Rick Violet
- *
- * Copyright: © 1992-1994 by Apple Computer, Inc., all rights reserved.
- *
- * Change History (most recent first):
- *
- * <2> 1/27/94 BD String utilities moved to TextUtils.h from Packages.h.
- * <1+> 1/27/94 BD Relstring moved to TextUtils.h from Packages.h.
- * <1+> 4/14/93 RV
- * <5+> 11/19/92 RV
- * 11/18/92 RV xxx put comment here xxx
- *
- * To Do:
- */
-
- #ifndef __MiscServices__
- #include "MiscServices.h"
- #endif
-
- #ifndef __Application__
- #include "Application.h"
- #endif
-
- #ifndef __TEXTUTILS__
- #include <TextUtils.h>
- #endif
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // AddService::AddService - constructor.
- //—————————————————————————————————————————————————————————————————————————————————————
- AddService::AddService():Service( "Add" )
- {
- }
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // AddService::~AddService - destructor.
- //—————————————————————————————————————————————————————————————————————————————————————
- AddService::~AddService()
- {
- }
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // AddService::ProcessRequest - implement Addition of V.U. Numbers
- //—————————————————————————————————————————————————————————————————————————————————————
- OSErr
- AddService::ProcessRequest( Request* pReq )
- {
- OSErr tErr = noErr;
- ScriptValue* tNum1;
- ScriptValue* tNum2;
- short tResult;
- ValueKind tVKind;
-
- //———— Get the first parameter
- tVKind = kVUNumberKind;
- tErr = pReq->GetNthParam( 1, tNum1, tVKind );
-
- //———— Did we get a valid ScriptValue object pointer?
- if( tErr || (tNum1 == nil))
- {
- //———— No, bail out
- pReq->SetErrorCode( paramErr );
- pReq->SetErrorMessage( "Failed to extract parameter 1" );
- return paramErr;
- }
-
- //———— Get the second parameter
- tVKind = kVUNumberKind;
- tErr = pReq->GetNthParam( 2, tNum2, tVKind );
-
- //———— Did we get a valid ScriptValue object pointer?
- if( tErr || (tNum1 == nil))
- {
- //———— No, bail out
- pReq->SetErrorCode( paramErr );
- pReq->SetErrorMessage( "Failed to extract parameter 2" );
- return paramErr;
- }
-
- //———— The parameters are of the correct type
- //———— add them and return the result to V.U.
- tResult = ((VUNumber*)tNum1)->GetNumber();
- tResult += ((VUNumber*)tNum2)->GetNumber();
-
- pReq->SetReturnValue( tResult );
- return noErr;
- }
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // EchoService::EchoService - constructor.
- //—————————————————————————————————————————————————————————————————————————————————————
- EchoService::EchoService():Service( "Echo")
- {
- }
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // EchoService::~EchoService - destructor.
- //—————————————————————————————————————————————————————————————————————————————————————
- EchoService::~EchoService()
- {
- }
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // EchoService::ProcessRequest - echo the parameters back
- //—————————————————————————————————————————————————————————————————————————————————————
- OSErr
- EchoService::ProcessRequest( Request* pReq )
- {
- OSErr tErr = noErr;
- ScriptValue* tVal;
- VUList* tReturnList;
- short tParamCount;
- short i;
- ValueKind tVKind;
-
- tParamCount = pReq->GetParamCount();
-
- if( tParamCount == 1 )
- {
- tVKind = kVUAnyKind;
- tErr = pReq->GetNthParam( 1, tVal, tVKind );
- if( tVal && !tErr )
- {
- pReq->SetReturnValue( tVal->Clone() );
- }
- else
- {
- tErr = memFullErr;
- }
- }
- else
- {
- tReturnList = new VUList();
- if( tReturnList )
- {
- for( i = 1; i <= tParamCount; i++ )
- {
- tVKind = kVUAnyKind;
- tErr = pReq->GetNthParam( i, tVal, tVKind );
- if( tVal && (tErr == noErr) )
- {
- tReturnList->PutNthItem( tVal->Clone(), i );
- }
- }
- pReq->SetReturnValue( tReturnList );
- }
- }
- return tErr;
- }
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // ErrorService::ErrorService - constructor.
- //—————————————————————————————————————————————————————————————————————————————————————
- ErrorService::ErrorService():Service( "Error")
- {
- }
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // ErrorService::~ErrorService - destructor.
- //—————————————————————————————————————————————————————————————————————————————————————
- ErrorService::~ErrorService()
- {
- }
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // ErrorService::ProcessRequest - Error the parameters back
- //—————————————————————————————————————————————————————————————————————————————————————
- OSErr
- ErrorService::ProcessRequest( Request* pReq )
- {
- OSErr tErr = noErr;
- ScriptValue* tNum1;
- ScriptValue* tNum2;
- short tErrCode;
- char* tErrString;
- ValueKind tVKind;
-
- //———— Get the first parameter, the code to return
- tVKind = kVUNumberKind;
- tErr = pReq->GetNthParam( 1, tNum1, tVKind );
-
- //———— Did we get a valid ScriptValue object pointer?
- if( tErr || (tNum1 == nil))
- {
- //———— No, bail out
- pReq->SetErrorCode( paramErr );
- pReq->SetErrorMessage( "Failed to extract parameter 1" );
- return paramErr;
- }
- else
- {
- tErrCode = ((VUNumber*)tNum1)->GetNumber();
- pReq->SetErrorCode( tErrCode );
- }
-
- //———— Get the second parameter, the string to return
- tVKind = kVUStringKind;
- tErr = pReq->GetNthParam( 2, tNum2, tVKind );
-
- //———— Did we get a valid ScriptValue object pointer?
- if( tErr || (tNum2 == nil))
- {
- //———— No, bail out
- pReq->SetErrorCode( paramErr );
- pReq->SetErrorMessage( "Failed to extract parameter 2" );
- return paramErr;
- }
- else
- {
- tErrString = ((VUString*)tNum2)->GetText();
- pReq->SetErrorMessage( tErrString );
- }
- return noErr;
- }
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // WaitService::WaitService - constructor.
- //—————————————————————————————————————————————————————————————————————————————————————
- WaitService::WaitService():Service( "Wait" )
- {
- }
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // WaitService::~WaitService - destructor.
- //—————————————————————————————————————————————————————————————————————————————————————
- WaitService::~WaitService()
- {
- }
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // WaitService::ProcessRequest - Wait the parameters back
- //—————————————————————————————————————————————————————————————————————————————————————
- OSErr
- WaitService::ProcessRequest( Request* pReq )
- {
- unsigned long tStopTicks;
- short tWaitInterval;
- ScriptValue* tParam;
- Boolean tCanceled = false;
- ValueKind tVKind;
- OSErr tErr;
-
-
- //———— Get the first parameter
- tVKind = kVUNumberKind;
- tErr = pReq->GetNthParam( 1, tParam, tVKind );
-
- //———— Did we get a valid ScriptValue object pointer?
- if( tParam == nil || tErr )
- {
- //———— No, bail out
- pReq->SetErrorCode( paramErr );
- pReq->SetErrorMessage( "Failed to extract parameter 1" );
- return paramErr;
- }
-
- tWaitInterval = ((VUNumber*)tParam)->GetNumber() * 60; //———— Convert seconds to Ticks
-
- tStopTicks = TickCount() + tWaitInterval;
- while( (TickCount() < tStopTicks) && (!tCanceled) )
- {
- if( CheckForCancel( pReq ) )
- {
- tCanceled = true;
- }
- }
-
- if( tCanceled )
- {
- pReq->SetReturnValue( "Canceled" );
- }
- else
- {
- pReq->SetReturnValue( "Not Canceled" );
- }
- }
-